
ALTER  proc sp_get_odm_list
@customerId int
as
begin

	declare @results Table(Customer_ID int, Customer_Name varchar(100), Flag varchar(10) )
	
	insert into @results(Customer_ID, Customer_Name )  select  ctp.Customer_ID, C_Name from Customer, Customer_Type_Relationship ctp, Customer_Types ct 
	where C_Disabled = 1 and ct.C_Type_Id = 2 and ct.C_Type_ID = ctp.C_Type_ID and ctp.Customer_ID = Customer.Customer_ID and Customer.Customer_ID <> @customerId order by C_Name
	
	declare odmList CURSOR for select  cor.ODMCustomer_ID from Customer_ODM_Relationship cor, Customer_Relationship_Status crs where ParentCustomer_ID = @customerId and cor.RelationshipStatus_ID = crs.RelationshipStatus_ID and crs.Name = 'Active'
	declare @odm_customer_id int

	open odmList
		fetch next from odmList into @odm_customer_id
		while @@fetch_Status = 0
		begin
			update @results set Flag = 'checked' where Customer_ID = @odm_customer_id
			fetch next from odmList into @odm_customer_id
		end
	close odmList
	deallocate odmList
	
	select *from @results
end


